﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace itau.im.gerador
{
    public class CalculosPMT
    {
        public double CalcularValorPresente(double valorDaParcela, double fator)
        {
            return (double)valorDaParcela / fator;
        }

        public double CalcularValorFuturo(double fator, double fatorAnterior, double saldoDevedor)
        {
            return (((double)fator / fatorAnterior - 1) * saldoDevedor + 1);
        }

        public double CalcularTIR(int somaDias, double somaValorPresente, double somaValorParcelas, int contadorParcelas, int baseDias)
        {
            return (double)((Math.Pow(((double)somaValorParcelas / somaValorPresente), ((double)baseDias / ((double)somaDias / contadorParcelas)))) - 1);
        }

        public double CalcularPercentualCDI(double TIRBullet, double TIRBase)
        {
            return (double)(Math.Pow((1 + TIRBullet), ((double)1 / 252)) - 1) / (Math.Pow((1 + TIRBase), ((double)1 / 252)) - 1) * 100;
        }

        public double CalcularCDIMais(double TIRBullet, double TIRBase)
        {
            return ((double)(TIRBullet + 1) / (TIRBase + 1) - 1) * 100;
        }

        public double AproximarValorTIR(double estimativaTIRInicial, double estimativaTIR, double diferencaSomaVPEstimativaTIR, double diferencaSomaVPEstimativaTIRAnterior)
        {
            return (estimativaTIRInicial - ((double)(diferencaSomaVPEstimativaTIRAnterior * (estimativaTIRInicial - estimativaTIR)) / (diferencaSomaVPEstimativaTIRAnterior - diferencaSomaVPEstimativaTIR)));
        }
    }
}
